package com.wlz.multi;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;

public class ReactorServer {
    public static void main(String[] args) throws IOException {
        Selector selector;//事件轮询器   对select、poll、epoll封装
        ServerSocketChannel serverSocketChannel;
        selector = Selector.open(); //打开一个Selector
        serverSocketChannel = ServerSocketChannel.open(); //建立一个Server端通道
        serverSocketChannel.socket().bind(new InetSocketAddress(8080)); //绑定服务端口
        serverSocketChannel.configureBlocking(true); //selector模式下，所有通道必须是非阻塞的
        //Reactor是入口，最初给一个channel注册上去的事件都是accept

        new Thread(new Acceptor(serverSocketChannel),"reactor-001").start();
    }
}
